package cn.u313.entry;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * 涩图表
 */
@Entity
@Table(name = "t_dongman_2")
public class StuDataEntry {
    private String author;
    @Id
    @Column(name = "id_1")
    private int id;
    private int p;
    private long pid;
    private String quickUrl;
    private String tags;
    private String title;
    private int uid;
    private String url;
    public void setAuthor(String author) {
        this.author = author;
    }
    public String getAuthor() {
        return author;
    }

    public void setId(int id) {
        this.id = id;
    }
    public int getId() {
        return id;
    }

    public void setP(int p) {
        this.p = p;
    }
    public int getP() {
        return p;
    }

    public void setPid(long pid) {
        this.pid = pid;
    }
    public long getPid() {
        return pid;
    }

    public void setQuickUrl(String quickUrl) {
        this.quickUrl = quickUrl;
    }
    public String getQuickUrl() {
        return quickUrl;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }
    public String getTags() {
        return tags;
    }

    public void setTitle(String title) {
        this.title = title;
    }
    public String getTitle() {
        return title;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }
    public int getUid() {
        return uid;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    public String getUrl() {
        return url;
    }

    private String e(String str){
        try {
            return URLEncoder.encode(str,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "error";
        }
    }
    private String d(String str){
        try {
            return URLDecoder.decode(str,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "error";
        }
    }
    public StuDataEntry encode() {
        author=e(author);
        this.tags=e(tags);
        this.tags=e(tags);
        this.title=e(title);
        return  this;
    }
    public StuDataEntry decode() {
        author=d(author);
        this.tags=d(tags);
        this.tags=d(tags);
        this.title=d(title);
        return  this;
    }

    @Override
    public String toString() {
        return "StuData{" +
                "author='" + author + '\'' +
                ", id=" + id +
                ", p=" + p +
                ", pid=" + pid +
                ", quickUrl='" + quickUrl + '\'' +
                ", tags='" + tags + '\'' +
                ", title='" + title + '\'' +
                ", uid=" + uid +
                ", url='" + url + '\'' +
                '}';
    }
}
